//
//  DHS2_ActivityDetailController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/5/7.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHS2_ActivityDetailController.h"

@interface DHS2_ActivityDetailController ()<UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *coverImageView;
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) NSDictionary *model; //数据源
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contenViewHeightLayout;

@end

@implementation DHS2_ActivityDetailController

- (instancetype)initWithDic:(NSDictionary *)model
{
    self = [super init];
    if (self) {
        self.model = model;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titleLabel.text = @"活动";
    self.subTitleLabel.text = [self.model objectForKey:@"title"];
    [self.coverImageView sd_setImageWithURL:[self.model objectForKey:@"cover"]];
    
    NSDate *date = [NSDate dateWithServerISOString:[self.model objectForKey:@"createdAt"] format:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
    self.timeLabel.text = [NSDate stringFromDate:date withFormat:@"yyyy/MM/dd HH:mm"];
    
    self.webView.delegate = self;
    [self.webView loadHTMLString:[self.model objectForKey:@"content"] baseURL:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    self.scrollView.contentSize = CGSizeMake(kScreenWidth, 233 + webView.scrollView.contentSize.height);
    self.contenViewHeightLayout.constant = self.scrollView.contentSize.height;
}

@end
